package com.dq.Week1.day05.homeWork2;

import java.util.Arrays;

public class StudentUtil {
    Student[] students = {};

    int index = 0;

    public boolean login(String username,String password)
    {
        for (int i = 0; i < index;i++) {
            if(username.equals(students[i].getUsername()) && password.equals(students[i].getPassword()))
            {
                return true;
            }
        }
        return false;
    }
    public boolean register(String username,String password)
    {
        if(exist(username)){
            return false;
        }
        if(index == students.length)
        {
            students = Arrays.copyOf(students, students.length + 5);
        }

        Student student = new Student(username,password);
        students[index] = student;
        index++;

        return true;
    }

    public boolean exist(String username)
    {
        for (int i = 0; i < index; i++) {
            if(username.equals(students[i].getUsername()))
            {
                return true;
            }
        }
      return false;
    }
}
